<div class="root">
  <div class="header">
    <div class="first-row">
      <div i18n class="title">Save to</div>
    </div>
  </div>

  <div class="input-container">
    <input type="text" placeholder="Search playlists" i18n-placeholder [(ngModel)]="videoPlaylistSearch" (ngModelChange)="onVideoPlaylistSearchChanged()" />
  </div>

  <div class="playlists">
    <div
      *ngFor="let playlist of videoPlaylists"
      class="playlist dropdown-item" [ngClass]="{ 'has-optional-row': playlist.optionalRowDisplayed }"
    >
      <div class="primary-row" (click)="toggleMainPlaylist($event, playlist)">
        <my-peertube-checkbox
          [disabled]="isPresentMultipleTimes(playlist) || playlist.optionalRowDisplayed" [inputName]="getPrimaryInputName(playlist)"
          [ngModel]="isPrimaryCheckboxChecked(playlist)" [onPushWorkaround]="true"
        ></my-peertube-checkbox>

        <label class="display-name">
          {{ playlist.displayName }}
        </label>

        <div class="optional-row-icon" *ngIf="isPrimaryCheckboxChecked(playlist)" (click)="$event.stopPropagation(); toggleOptionalRow(playlist)">
          <my-global-icon iconName="add" aria-hidden="true"></my-global-icon>
        </div>
      </div>

      <div class="optional-rows" *ngIf="playlist.optionalRowDisplayed">
        <div class="labels">
          <div i18n>Start at</div>
          <div i18n>Stop at</div>
        </div>

        <div *ngFor="let element of buildOptionalRowElements(playlist)">
          <my-peertube-checkbox
            [inputName]="getOptionalInputName(playlist, element)"
            [ngModel]="element.enabled" [onPushWorkaround]="true"
            (click)="toggleOptionalPlaylist($event, playlist, element, startAt.timestamp, stopAt.timestamp)"
          ></my-peertube-checkbox>

          <my-timestamp-input
            [maxTimestamp]="video.duration"
            [(ngModel)]="element.startTimestamp"
            (inputBlur)="onElementTimestampUpdate(playlist, element)"
            #startAt
          ></my-timestamp-input>

          <my-timestamp-input
            [maxTimestamp]="video.duration"
            [(ngModel)]="element.stopTimestamp"
            (inputBlur)="onElementTimestampUpdate(playlist, element)"
            #stopAt
          ></my-timestamp-input>
        </div>
      </div>
    </div>
  </div>

  <div class="new-playlist-button dropdown-item" (click)="openCreateBlock($event)" [hidden]="isNewPlaylistBlockOpened">
    <my-global-icon iconName="add" aria-hidden="true"></my-global-icon>

    <span i18n>Create a private playlist</span>
  </div>

  <form class="new-playlist-block dropdown-item" *ngIf="isNewPlaylistBlockOpened" (ngSubmit)="createPlaylist()" [formGroup]="form">
    <div class="form-group">
      <label i18n for="displayName">Display name</label>
      <input
        type="text" id="displayName"
        formControlName="displayName" [ngClass]="{ 'input-error': formErrors['displayName'] }"
      >
      <div *ngIf="formErrors['displayName']" class="form-error">
        {{ formErrors['displayName'] }}
      </div>
    </div>

    <input type="submit" i18n-value value="Create" [disabled]="!form.valid">
  </form>
</div>
